package com.gopay.checkorder.service.proxy;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.checkorder.dao.BisBankOrderQueryDAO;
import com.gopay.checkorder.manager.BankOrderManager;
import com.gopay.checkorder.manager.BcdlKeyInfoManager;
import com.gopay.checkorder.service.BankOrderService;
import com.gopay.common.Result;
import com.gopay.common.constants.bank.BankConstants;
import com.gopay.common.constants.bank.BankOrderStatus;
import com.gopay.common.constants.bank.BisBankBusinessProd;
import com.gopay.common.constants.bank.BisBankInterfaceChannel;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.cps.manager.order.CpsGeneralMainOrderQueryManager;
import com.gopay.common.domain.bank.BankOrder;
import com.gopay.common.domain.bank.BaseDayendMessage;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.CheckOrderLog;
import com.gopay.common.domain.bank.dayend.BaseDayendEntry;
import com.gopay.common.domain.cps.CpsGenMainOrder;
import com.gopay.common.domain.cps.vo.CheckOrderResult;
import com.gopay.common.exception.GopayException;
import com.gopay.common.order.bankorder.trade.InitialSpringBeanName;
import com.gopay.common.order.bankorder.trade.TradeType;
import com.gopay.common.util.DateUtils;
import com.gopay.common.util.spring.SpringContextUtil;
import com.gopay.sms.client.GopaySMSHttpClient;
import com.gopay.sms.common.constants.SMSAppId;
import com.gopay.sms.common.domain.RequestVO;
import com.gopay.sms.common.domain.ResponseVO;

/**
 * 对单代理
 * 
 * @CheckOrderProxy.java
 * @author yaobo @2013-3-20 上午10:42:23 www.gopay.com.cn Inc.All rights reserved.
 */
public class CheckOrderProxy implements BankOrderService {
    private final static Logger logger = LoggerFactory.getLogger("CHECK_ORDER");

    @Resource(name = "bankOrderManager")
    protected BankOrderManager bankOrderManager;

    @Resource(name = "cpsGeneralMainOrderQueryManager")
    protected CpsGeneralMainOrderQueryManager mainOrderQuery;
    @Resource(name = "bcdlKeyInfoManager")
    BcdlKeyInfoManager bcdlKeyInfoManager;
    @Resource(name = "bisBankOrderQueryDAO")
    private BisBankOrderQueryDAO bisBankOrderQueryDAO;

    /**
     * 最大对单次数
     */
    protected int maxTotalCheckTimes;

    private static final String SWITCH_ON = "on";

    @Resource(name = "smsConfig")
    private Map<String, String> smsConfig;

    /**
     * 获取订单信息
     * 
     * @param base
     * @return
     * @throws GopayException
     */
    protected CpsGenMainOrder getMainOrder(String orderId) throws GopayException {
        // 获取主订单表
        CpsGenMainOrder mainOrder = mainOrderQuery.get(orderId);
        if (mainOrder == null) {
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E5041, "mainOrder is null");
        }

        return mainOrder;
    }

    @Override
    public CheckOrderResult checkOrder(BankOrder bankOrder, String target) {
        /*
         * if(StringUtils.equals(bankOrder.getBankCode(),"ICBC")){ //临时解决对账频繁乐观锁
         * bankOrder = bisBankOrderQueryDAO.find(BankOrder.class,
         * bankOrder.getOutOrderId()); logger.error("have a look, checkOrder: "
         * +bankOrder); }
         */
        CheckOrderResult checkOrderResult = new CheckOrderResult(false);
        if (bankOrder == null || StringUtils.isBlank(bankOrder.getOrderId())) {
            checkOrderResult.setErrCode(ProcCodeConstants.PROC_CODE_100E5060);
            logger.error("bankOrder is null or orderId is null.");
            return checkOrderResult;
        }
        checkOrderResult.setOrderId(bankOrder.getOrderId());
        try {

            // 判断退款订单是否为未受理状态
            if (BisBankBusinessProd._12.value.equals(bankOrder.getBankBizProdCode())
                    && BankOrderStatus.ACCEPTED.equals(bankOrder.getOrderStatus())) {
                logger.error("bank orderid: " + bankOrder.getOrderId() + ",订单状态: " + bankOrder.getOrderStatus()
                        + ",退款订单未发往银行，请耐心等待.");
                checkOrderResult.setErrCode(ProcCodeConstants.PROC_CODE_100E6108);
                checkOrderResult.setErrMsg("退款订单未发往银行，请耐心等待 .");
                return checkOrderResult;

            }
            // 锁定银行流水记录
            if (bankOrderManager.lock(bankOrder) == 0) {
                logger.error("CheckOrderProxy test1: ");
                checkOrderResult.setErrCode(ProcCodeConstants.PROC_CODE_100E5060);
                checkOrderResult.setErrMsg("bankOrder is unlock");
                logger.error(bankOrder.getOrderId() + " bankOrder is unlock.");
                return checkOrderResult;
            }
            logger.error(bankOrder.getOrderId() + " CheckOrderProxy totalchecktimes test: ");
            // 自动发起对单时,对单次数+1(状态不等于'入账失败')
            if (StringUtils.equals(BankOrderStatus.AUTO_CHECK_SUCCESS, target)
                    && !StringUtils.equals(BankOrderStatus.ENTER_ACCOUNT_FIAL, bankOrder.getOrderStatus())) {
                logger.error(
                        bankOrder.getOrderId() + " CheckOrderProxy totalchecktimes: " + bankOrder.getTotalCheckTimes());
                // bankOrder.setTotalCheckTimes(bankOrder.getTotalCheckTimes() +
                // 1);
                bankOrderManager.updateTotalCheckTimes(bankOrder);
            }

            logger.error(bankOrder.getOrderId() + " CheckOrderProxy totalchecktimes test1: ");

            /**
             * 去掉入账失败订单处理 "96"状态 lilili 20160526
             */
            /*
             * if (StringUtils.equals(BankOrderStatus.ENTER_ACCOUNT_FIAL,
             * bankOrder.getOrderStatus())) { CpsGenMainOrder mainOrder =
             * getMainOrder(bankOrder.getOrderId());
             * checkOrderResult.setOrderId(mainOrder.getGopayOrderId());
             * checkOrderResult.setAmount(mainOrder.getMerTxnAmt()); InAccInfo
             * accInfo = new InAccInfo();
             * accInfo.setOrderId(bankOrder.getOrderId());
             * accInfo.setAmount(mainOrder.getMerTxnAmt());
             * accInfo.setRetCode("00");
             * accInfo.setCardType(BankCardType.Unknown.toString());
             * checkOrderResult.setAccInfo(accInfo);
             * checkOrderResult.setSuccess(true); } else {
             */
            // 继续对账
            String beanName = null;

            if (bankOrder.getBankBizProdCode().equals(BisBankBusinessProd._12.value)) {
                beanName = getRefundBeanName(bankOrder, bankOrder.getBankCode());
            } else if(bankOrder.getBankBizProdCode().equals(BisBankBusinessProd._26.value)){
                beanName = getReverseBeanName(bankOrder, bankOrder.getBankCode());
            } else {
                beanName = getBeanName(bankOrder.getInterfaceChennelCode(), bankOrder.getBankBizProdCode(),
                        bankOrder.getBankCode());
            }
            if (false == SpringContextUtil.containsBean(beanName)) {
                logger.error("spring bean does not exist: " + beanName);
                checkOrderResult.setErrCode(ProcCodeConstants.PROC_CODE_100E6044);
                return checkOrderResult;
            }

            BankOrderService checkOrderService = (BankOrderService) SpringContextUtil.getBean(beanName);
            checkOrderResult = checkOrderService.checkOrder(bankOrder, target);
            logger.error("checkOrderResult: " + ToStringBuilder.reflectionToString(checkOrderResult));
            /* } */


			if (checkOrderResult.isSuccess()) {
				// 金额校验,跳过付款订单

                if (!StringUtils.equals(bankOrder.getBankBizProdCode(), BisBankBusinessProd._09.value)
                        && checkOrderResult.getAccInfo().getAmount().compareTo(bankOrder.getSendBankAmt()) != 0) {
                    logger.error("注意!!!金额不一致,bank = " + bankOrder.getBankCode() + ",gopayOrderId = "
                            + bankOrder.getOrderId());
                    sendSms4AmtInequality(bankOrder);
                    throw new GopayException(ProcCodeConstants.PROC_CODE_100E5079, "金额不一致");
                }

                logger.info("bank orderid: " + bankOrder.getOrderId() + ",银行对账成功");
                // 入账
                if (!bankOrderManager.inAcct(checkOrderResult)) {
                    logger.info("bank orderid: " + bankOrder.getOrderId() + ",银行订单入账失败");
                    // 入账不成功，对单失败
                    checkOrderResult.setErrCode(ProcCodeConstants.PROC_CODE_100E5062);
                    checkOrderResult.setErrMsg("enter account fail.");
                    checkOrderResult.setSuccess(false);
                    logger.error("bank orderid: " + bankOrder.getOrderId() + ",notify cashier failure!!!");
                    // 入账失败,状态更新96,去掉此逻辑 by lziehng 2016
                    // bankOrderManager.updateEnterAccountFail(bankOrder);
                    return checkOrderResult;
                } else {
                    logger.info("bank orderid: " + bankOrder.getOrderId() + ",入账成功更新银行订单");
                    // 对单成功
                    bankOrderManager.updateSuccess(bankOrder, target);
                    checkOrderResult.setSuccess(true);
                    logger.error("bank orderid: " + bankOrder.getOrderId() + ",notify cashier success!!!");
                }
            } else if (checkOrderResult.isBankFailure()) {
                // 银行订单失败
                if (!bankOrder.getBankBizProdCode().equals(BisBankBusinessProd._09.value)) {
                    checkOrderResult.setErrCode(ProcCodeConstants.PROC_CODE_100E5062);
                    checkOrderResult.setErrMsg("enter bank fail.");
                }

                checkOrderResult.setSuccess(false);
                logger.error("bank orderid: " + bankOrder.getOrderId() + ",bank return failure!!!");
                if (BisBankBusinessProd._12.value.equals(bankOrder.getBankBizProdCode())
                        || BisBankBusinessProd._05.value.equals(bankOrder.getBankBizProdCode())
                        || BisBankBusinessProd._15.value.equals(bankOrder.getBankBizProdCode())
                        || BisBankBusinessProd._26.value.equals(bankOrder.getBankBizProdCode())) {
                    // 快捷失败通知cashier入账 add by zhengxue 20170313
                    // 退款失败通知cashier入账 add by zhengxue 20160906
                    bankOrderManager.inAcct(checkOrderResult);
                    bankOrder.setRemark2(checkOrderResult.getErrMsg()); // 记录失败原因
                }
                // 入账失败,状态更新99
                bankOrderManager.updateFail(bankOrder);
                return checkOrderResult;
            }

        } catch (Exception e) {
            logger.error(bankOrder.getOrderId() + "checkOrder error message: ", e);
        } finally {
            // 解锁
            bankOrderManager.unlock(bankOrder);
        }

        try {
            // 更新自动对账日志记录表
            CheckOrderLog checkOrderLog = new CheckOrderLog();
            checkOrderLog.setOutOrderId(bankOrder.getOutOrderId());
            if (checkOrderResult.isSuccess()) {
                checkOrderLog.setIsCheckOk(1);
                // 对账成功赋值errcode，为日志记录做准备
                checkOrderResult.setErrCode("SUCCESS");
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
            Date date;
            date = format.parse(format.format(new Date()));
            // 自动发起对单时,对单次数+1(状态不等于'入账失败')
            if (StringUtils.equals(BankOrderStatus.AUTO_CHECK_SUCCESS, target)
                    && !StringUtils.equals(BankOrderStatus.ENTER_ACCOUNT_FIAL, bankOrder.getOrderStatus())) {
                if (bankOrder.getTotalCheckTimes() > 0) {
                    if (bankOrder.getTotalCheckTimes() == 1) {
                        checkOrderLog.setRespcode(checkOrderResult.getErrCode());
                        checkOrderLog.setChecktime(date);
                        checkOrderLog.setCheckCount(bankOrder.getTotalCheckTimes());
                        bankOrderManager.insertCheckOrderLog(checkOrderLog);
                        logger.error("新增完成checkOrderLog日志表");
                    } else {
                        bankOrderManager.updateCheckOrderLog(checkOrderLog, checkOrderResult.getErrCode(), date,
                                bankOrder.getTotalCheckTimes());
                        logger.error("更新完成checkOrderLog日志表");
                    }
                }
            }
        } catch (Exception e) {
            logger.error("checkOrder updateLog error.", e);
        }

        return checkOrderResult;
    }
   	
	public String getRefundBeanName(BankOrder bankOrder, String bankCode) throws GopayException {
		String beanName = "";
		// 获取原银行退款订单
		BankOrder oriBankOrder = bankOrderManager.getByGopayOutOrderId(bankOrder.getOriOutOrderId());
		if (oriBankOrder == null) {
			throw new GopayException(ProcCodeConstants.PROC_CODE_100E5041);
		}
		String beanSuffix = TradeType.getOrderTrandType(oriBankOrder.getBankBizProdCode());
		bankCode = InitialSpringBeanName.getOutStlmCd(bankOrder.getInterfaceChennelCode(),
				bankOrder.getBankBizProdCode(), bankCode);	
		beanName = bankCode + "-" + beanSuffix + "-REFUND";
		// add by jxj
		if(oriBankOrder.getBankBizProdCode().equals(BisBankBusinessProd._16.value)){
			if(StringUtils.equals(oriBankOrder.getInterfaceChennelCode(), BisBankInterfaceChannel._17.value)){
				beanName = beanName +  "-" + BankConstants.BANK_LOGO_CMBC;
			}
			if (StringUtils.equals(oriBankOrder.getInterfaceChennelCode(), BisBankInterfaceChannel._25.value)) {
                beanName = beanName + "-" + BankConstants.BANK_LOGO_PAB;
            }
			if(StringUtils.equals(oriBankOrder.getInterfaceChennelCode(), BisBankInterfaceChannel._28.value)){
				beanName = beanName +  "-" + BankConstants.BANK_LOGO_SPDB;
			}
		}
		if(oriBankOrder.getBankBizProdCode().equals(BisBankBusinessProd._18.value)){
			if(bankOrder.getInterfaceChennelCode().equals(BisBankInterfaceChannel._15.value)){
				beanName = beanName + "-" + BankConstants.BANK_LOGO_CITIC;
			}
			if(bankOrder.getInterfaceChennelCode().equals(BisBankInterfaceChannel._17.value)){
				beanName = beanName + "-" + BankConstants.BANK_LOGO_CMBC;
			}
            if (bankOrder.getInterfaceChennelCode().equals(BisBankInterfaceChannel._25.value)) {
                beanName = beanName + "-" + BankConstants.BANK_LOGO_PAB;
            }
        	if(StringUtils.equals(oriBankOrder.getInterfaceChennelCode(), BisBankInterfaceChannel._28.value)){
				beanName = beanName +  "-" + BankConstants.BANK_LOGO_SPDB;
			}
        }
		if(oriBankOrder.getBankBizProdCode().equals(BisBankBusinessProd._25.value)){
			if(StringUtils.equals(oriBankOrder.getInterfaceChennelCode(), BisBankInterfaceChannel._25.value)){
				beanName = beanName +  "-" + BankConstants.BANK_LOGO_PAB;
			}
			if(StringUtils.equals(oriBankOrder.getInterfaceChennelCode(), BisBankInterfaceChannel._28.value)){
				beanName = beanName +  "-" + BankConstants.BANK_LOGO_SPDB;
			}
		}
		return beanName;
	}
	
	public String getReverseBeanName(BankOrder bankOrder, String bankCode) throws GopayException {
	    String beanName = "";
	    //获取银行原支付订单
	    BankOrder oriBankOrder = bankOrderManager.getByGopayOutOrderId(bankOrder.getOriOutOrderId());
        if (oriBankOrder == null) {
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E5041);
        }
        String beanSuffix = TradeType.getOrderTrandType(oriBankOrder.getBankBizProdCode());
        bankCode = InitialSpringBeanName.getOutStlmCd(bankOrder.getInterfaceChennelCode(),
                bankOrder.getBankBizProdCode(), bankCode);  
        beanName = bankCode + "-" + beanSuffix + "-REVERSE";
        if (oriBankOrder.getBankBizProdCode().equals(BisBankBusinessProd._25.value)) {          
            if(StringUtils.equals(oriBankOrder.getInterfaceChennelCode(), BisBankInterfaceChannel._25.value)){
            	 beanName = beanName + "-" + BankConstants.BANK_LOGO_PAB;
     		}
            if(StringUtils.equals(oriBankOrder.getInterfaceChennelCode(), BisBankInterfaceChannel._28.value)){
     			beanName = beanName +  "-" + BankConstants.BANK_LOGO_SPDB;
     		}
        }
        return beanName;
	}
    /**
     * 获取SPRING加载的BeanName
     * 
     * <pre>
     * BeanName规范:银行编码-交易类型，如TBANK-B2B
     * </pre>
     * 
     * @param mainOrder
     *            订单信息
     * @param bankInfo
     *            银行信息
     * @return
     * @throws GopayException
     */
    private String getBeanName(String inChann, String bankBusProd, String bankCode) throws GopayException {
        String beanName = "";
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._00.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-B2C";
        }
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._01.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCdForNucc(inChann, bankCode);//网联B2B添加了通道
            beanName = bankCode + "-B2B";
        }
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._09.value, bankBusProd)) {
            beanName = bankCode + "-BCDL";
        }
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._05.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-EXPAY";
        }
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._11.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-B2C";
        }
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._15.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-EXPAY";
        }
		if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._16.value, bankBusProd)) {
			bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
			beanName = bankCode + "-SCAN";
			// add by jxj 添加对民生扫码支付的判断
			if (StringUtils.equals(inChann, BisBankInterfaceChannel._17.value)) {
				beanName = beanName + "-" + BankConstants.BANK_LOGO_CMBC;
			}
			if (StringUtils.equals(inChann, BisBankInterfaceChannel._25.value)) {
				beanName = beanName + "-" + BankConstants.BANK_LOGO_PAB;
			}
			if (StringUtils.equals(inChann, BisBankInterfaceChannel._28.value)) {
				beanName = beanName + "-" + BankConstants.BANK_LOGO_SPDB;
			}
		}
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._17.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-SDK";
            if (inChann.equals(BisBankInterfaceChannel._25.value)) {
                beanName = beanName + "-" + BankConstants.BANK_LOGO_PAB;
            }
            if (StringUtils.equals(inChann, BisBankInterfaceChannel._28.value)) {
				beanName = beanName + "-" + BankConstants.BANK_LOGO_SPDB;
			}
        }
        /**
         * 宣广海修改统一走退款获取beanName方法 if
         * (StringUtils.equals(com.gopay.common.constants.bank.
         * BisBankBusinessProd._12.value, bankBusProd)) { bankCode =
         * InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
         * beanName = bankCode + "-REFUND"; }
         **/
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._18.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-WCPAY";
            if (inChann.equals(BisBankInterfaceChannel._15.value)) {
                beanName = beanName + "-" + BankConstants.BANK_LOGO_CITIC;
            }
            if (inChann.equals(BisBankInterfaceChannel._17.value)) {
                beanName = beanName + "-" + BankConstants.BANK_LOGO_CMBC;
            }
            if (inChann.equals(BisBankInterfaceChannel._25.value)) {
                beanName = beanName + "-" + BankConstants.BANK_LOGO_PAB;
            }
            if (StringUtils.equals(inChann, BisBankInterfaceChannel._28.value)) {
				beanName = beanName + "-" + BankConstants.BANK_LOGO_SPDB;
			}
        }
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._20.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-EXPAY";
        }
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._21.value, bankBusProd)) {
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-EXPAY";
        }
        if(StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._25.value, bankBusProd)){
            bankCode = InitialSpringBeanName.getOutStlmCd(inChann, bankBusProd, bankCode);
            beanName = bankCode + "-MICRO";
            if (inChann.equals(BisBankInterfaceChannel._25.value)) {
                beanName = beanName + "-" + BankConstants.BANK_LOGO_PAB;
            }
            if (StringUtils.equals(inChann, BisBankInterfaceChannel._28.value)) {
				beanName = beanName + "-" + BankConstants.BANK_LOGO_SPDB;
			}
        }
        return beanName;
    }

    public void setMaxTotalCheckTimes(int maxTotalCheckTimes) {
        this.maxTotalCheckTimes = maxTotalCheckTimes;
    }

    public boolean isBcdlOrder(String bankBusProd) {
        if (StringUtils.equals(com.gopay.common.constants.bank.BisBankBusinessProd._09.value, bankBusProd)) {
            return true;
        }
        return false;
    }

    @Override
    public BankOrder getDbOrder() {
        return null;
    }

    /**
     * @author guomuye
     */
    @Override
    public List<CheckOrderResult> checkDayend(String bank_bus) {

        List<CheckOrderResult> checkOrderReList = new ArrayList<>();
        if (false == SpringContextUtil.containsBean(bank_bus)) {
            CheckOrderResult checkOrderResult = new CheckOrderResult(false);
            logger.error("spring bean does not exist: " + bank_bus);
            checkOrderResult.setErrCode(ProcCodeConstants.PROC_CODE_300G1011);
            checkOrderResult.setErrMsg(bank_bus + ":spring获得checkOrderImpl调用类失败");
            checkOrderReList.add(checkOrderResult);
            return checkOrderReList;
        }

        BankOrderService checkOrderService = (BankOrderService) SpringContextUtil.getBean(bank_bus);
        // 远程调用出来的银行日终
        // BOC-B2C
        Result re = checkOrderService.getDayendMsg(bank_bus);
        if (!re.isSuccess()) {
            logger.error(bank_bus + "::" + re.getResultCode() + "::" + re.getErrorMsg());
            CheckOrderResult checkOrderResult = new CheckOrderResult(false);
            checkOrderResult.setErrCode(re.getResultCode());
            checkOrderResult.setErrMsg(bank_bus + "::远端bis调用异常" + re.getErrorMsg());
            checkOrderReList.add(checkOrderResult);
            return checkOrderReList;
        }
        BaseDayendMessage base = (BaseDayendMessage) re.getDefaultModel();
        List<BaseDayendEntry> dayendOrderList = base.getDayendList();
        for (int i = 0; i < dayendOrderList.size(); i++) {
            BaseDayendEntry dayendModel = dayendOrderList.get(i);
            BankOrder bo = bankOrderManager.getByGopayOutOrderId(dayendModel.getOrderNo());
            if (bo == null) {
                continue;
            } else {
                logger.error("boc b2c dayend entry:" + dayendModel);
                CheckOrderResult checkOrderResult = checkOrderService.checkDayendOrder(dayendModel, bo);

                if (!checkOrderResult.isSuccess()) {
                    checkOrderReList.add(checkOrderResult);
                }
            }
        }
        if (checkOrderReList != null && checkOrderReList.size() == 0) {
            CheckOrderResult checkOrderResult = new CheckOrderResult();
            checkOrderResult.setSuccess(true);
            checkOrderResult.setErrMsg("本日无失败订单");
            checkOrderReList.add(checkOrderResult);
            logger.info("中行本日对账无失败订单");

        }
        return checkOrderReList;
    }

    @Override
    public BaseMessage dayend(String bank_bus) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public CheckOrderResult checkDayendOrder(BaseDayendEntry bdm, BankOrder bo) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Result getDayendMsg(String string) {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * 订单金额不一致,发送报警短信
     * 
     * @param gopayOrderId
     */
    private void sendSms4AmtInequality(BankOrder bankOrder) {

        try {
            if (SWITCH_ON.equals(smsConfig.get("switch"))) {
                // 自定义短信内容，不提供验证码校验功能
                RequestVO req = new RequestVO();
                req.setAppId(SMSAppId._90000.value);
                req.setMobile(smsConfig.get("mobile"));// 电话号码(多个以逗号分隔)
                req.setContent(DateUtils.getCurrDate() + "订单金额不一致,bank:" + bankOrder.getBankCode() + ",gopayOrderId:"
                        + bankOrder.getOrderId());
                ResponseVO resp = GopaySMSHttpClient.getInstance().createVerificationCode(req);

                if (resp != null) {
                    if ("100".equals(resp.getStatusCode())) {
                        logger.error("[amt_inequality]订单金额不一致短信发送成功");
                    } else {
                        logger.error("[amt_inequality]订单金额不一致短信发送失败，原因：" + resp.getMessage());
                    }
                }
            } else {
                logger.error("[amt_inequality] 订单金额不一致已关闭");

            }
        } catch (Exception e) {
            logger.error("[sentinel_sms]senSMS error: ", e);
        }

    }
}